<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>
      Pomelo
    </title>
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
    <meta http-equiv="content-style-type" content="text/css" />
    <meta http-equiv="content-scripte-type" content="text/javascript" />
    <meta name="author" content="netease" />
    <meta name="version" content="1.0" />
    <meta name="keywords" content="pomelo" />
    <link type="text/css" rel="stylesheet" href="css/base.css" />
    <script src="js/lib/build/build.js" type="text/javascript"></script>
    <script type="text/javascript">
      require('boot');
    </script> 
    <script type="text/javascript">
      var pomelo = window.pomelo;
      // var host = "127.0.0.1"        //
      var host = "lrs.yataie.com"; //本地服务器
      //host = "120.77.157.99"     //热更新服务器
      //host = "39.108.225.227"      //欢乐赢棋牌服务器
      //host = "39.108.139.132"      //CentOs服务器
      //host = "nnapi.5d8d.com"; //我爱牛牛服务器
      //host = "119.23.216.86"
      //host = "pdkgame.5d8d.com"
      //host = "yy.njhuajia.com"
      var port = "3910";
      function show() {
          pomelo.request("connector.entryHandler.getNotify",null, function(data) {
              console.log(data)
          });
      }
      pomelo.on("onMessage",function(data) {
        console.log("onMessage")
        console.log(data)
      })
      pomelo.on("onNotify",function(data) {
        console.log("onNotify")
        console.log(data)
      })
      pomelo.on("disconnect",function(data) {
        // body...
        console.log("disconnect")
      })
      pomelo.on("close",function(data) {
        console.log("close")
      })
      pomelo.on("heartbeat timeout",function(data) {
        // body...
        console.log("heartbeat timeout")
      })
      pomelo.on("io-error",function(data) {
        // body...
        console.log("io-error")
        console.log(data)
      })

      //登录
      var vlogin = function(uid) {
        queryEntry(uid,function(host, port) {
          pomelo.init({
            host: host,
            port: port,
            log: true
          }, function() {
            var route = "connector.entryHandler.visitorEnter";
            pomelo.request(route,{"uid" : uid,inviter : 10001}, function(data) {
              console.log("!!!!!")
              console.log(data)
              if(data.error) {
                console.log(data)
                return;
              }
            });
          });
        });
      }
      var sendData = function(code,params) {
          pomelo.request("connector.entryHandler.sendData", {"code" : code,"params" : params || {}}, function(data) {
              console.log(data)
            }
          );
      }
      //创建新游戏   wantRole 代表哪个椅子号的玩家要哪个身份
      var newRoom = function() {
          sendData("newRoom",{gameType : "LRS",wantRole : {"0" : "idiots"}})
      }
      //准备
      var ready = function() {
          sendData("ready")
      }
      //获取房间数据
      var getRoomInfo = function() {
          sendData("getRoomInfo")
      }
      //===================================法官操作================================//
      //开始游戏
      var startGame = function() {
          sendData("houseAction",{type : "startGame"})
      }
      //开始警上投票
      var beginSheriffVote = function() {
          sendData("houseAction",{type : "beginSheriffVote"})
      }
      //结束遗言
      var finishLastWords = function() {
          sendData("houseAction",{type : "finishLastWords"})
      }
      //开始放逐投票
      var beginBanishVote = function() {
          sendData("houseAction",{type : "beginBanishVote"})
      }
      //===================================角色操作================================//
      //狼人杀人
      var werewolfAction = function(target) {
        sendData("roleAction",{type : "kill",target : target || 0})
      }
      //预言家验人
      var seerAction = function(target) {
        sendData("roleAction",{type : 0,target : target || 0})
      }
      //女巫操作  type  "save"  : 救人   "poison"  毒人   毒人需要带上target目标
      var witchAction = function(type,target) {
        sendData("roleAction",{type : type,target : target || 0})
      }
      //猎人操作  开枪带走玩家
      var hunterAction = function(target) {
        sendData("roleAction",{type : 0,target : target || 0})
      }
      //狼人自爆
      var selfDestruction = function() {
        sendData("roleAction",{type : "boom"})
      }
      //===================================游戏操作================================//
      //报名竞选警长
      var runSheriffJoin = function() {
        sendData("gameAction",{type : "runSheriffJoin"})
      }
      //退水
      var quitElection = function() {
        sendData("gameAction",{type : "quitElection"})
      }
      //警长投票
      var sheriffVote = function(target) {
        sendData("gameAction",{type : "quitElection",target : target})
      }
      //放逐投票
      var banishVote = function(target) {
        sendData("gameAction",{type : "banishVote",target : target})
      }
      //移交警徽
      var sheriffChange = function(target) {
        sendData("gameAction",{type : "sheriffChange",target : target})
      }

      var queryEntry = function(uid,callback) {
        var route = 'gate.gateHandler.queryClientEntry';
        pomelo.init({
          host: host,
          port: "3910",
          log: true
        }, function(data) {
          console.log("!!!!!")
          console.log(data)
          pomelo.request(route, {
            uid: uid
          }, function(data) {
            console.log("11data !!!!")
            console.log(data)
            pomelo.disconnect();
            if(data.code === 500) {
              console.log(data)
              return;
            }
            callback(host, data.port);
          });
        });
      };
    </script>
  </head>
  <body>
    <div class="g-doc">
      <div class="g-button">
        <input id="test" type="button" value="登录" onclick="vlogin()"/>
        <input id="test" type="button" value="创建房间" onclick="newRoom()"/>
        <input id="test" type="button" value="准备" onclick="ready()"/>
        <input id="test" type="button" value="获取房间数据" onclick="getRoomInfo()"/>
        <input id="test" type="button" value="开始游戏" onclick="startGame()"/>
        <input id="test" type="button" value="开始警上投票" onclick="beginSheriffVote(1)"/>
        <input id="test" type="button" value="结束遗言" onclick="finishLastWords(1)"/>
        <input id="test" type="button" value="开始放逐投票" onclick="beginBanishVote()"/>
      </div>
      <div class="g-button">
        <input id="test" type="button" value="刀人" onclick="werewolfAction(1)"/>
        <input id="test" type="button" value="自爆" onclick="selfDestruction()"/>
        <input id="test" type="button" value="查验" onclick="seerAction(1)"/>
        <input id="test" type="button" value="女巫操作" onclick="witchAction('poison',5)"/>
        <input id="test" type="button" value="猎人开枪" onclick="hunterAction(1)"/>
        <input id="test" type="button" value="竞选警长" onclick="runSheriffJoin()"/>
        <input id="test" type="button" value="退水" onclick="quitElection()"/>
        <input id="test" type="button" value="警上投票" onclick="sheriffVote(0)"/>
        <input id="test" type="button" value="放逐投票" onclick="banishVote(0)"/>
        <input id="test" type="button" value="移交警徽" onclick="sheriffChange(10)"/>
      </div>
    </div>
  </body>
</html>
